package com.android.webframework.nav;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class RouteOverlay extends Overlay {

	private GeoPoint gp1, gp2;
	private boolean point;
	private int mPointColor = Color.BLUE;
	private int mRouteColor = Color.RED;
	
	//For a point
	public RouteOverlay(GeoPoint point) {
		gp1 = point;
		this.point = true;
	}
	
	//For a line
	public RouteOverlay(GeoPoint point1, GeoPoint point2) {
		gp1 = point1;
		gp2 = point2;
		this.point = false;
	}

	public void setPointColor(int mPointColor) {
		this.mPointColor = mPointColor;
	}

	public void setRouteColor(int mRouteColor) {
		this.mRouteColor = mRouteColor;
	}

	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {
		Projection projection = mapView.getProjection();
		Paint paint = new Paint();
		
		if(point && !shadow) {
			//Set up paint for the point
			paint.setColor(mPointColor);
			paint.setStrokeWidth(5);
			paint.setAlpha(180);
			//paint point
			Point point = new Point();
			projection.toPixels(gp1, point);
			canvas.drawCircle(point.x, point.y, 11, paint);
		} else if(!point && !shadow) {
			//Set up paint for path
			paint.setColor(mRouteColor);
			paint.setStrokeWidth(5);
			paint.setAlpha(120);
			//paint line
			Point point1 = new Point();
			projection.toPixels(gp1, point1);
			Point point2 = new Point();
			projection.toPixels(gp2, point2);
			canvas.drawLine(point1.x, point1.y, point2.x, point2.y, paint);
		}
		super.draw(canvas, mapView, shadow);
	}
	
}
